package org.zjt.traverse;

import io.reactivex.Flowable;
import io.reactivex.Single;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author juntao.zhang
 * @version V1.0
 * @Description: 迭代器 和 for each的比较
 * @Package org.zjt.traverse
 * @date 2018/6/11 22:54
 */
@Slf4j
public class SafeTraverse {

    public static void main(String[] args) {
        Single<List<Integer>> listSingle = Flowable.range(1, 5).toList();
        List<Integer> integers = listSingle.blockingGet();



        for(Iterator<Integer> iterator = integers.iterator();iterator.hasNext();){
            Integer next = iterator.next();
            log.info(" 此时指针执行下一个地址，并返回当前的元素 ",String.valueOf(next)  );
            iterator.remove();
        }

        // error ConcurrentModificationException
        for (Integer num : integers){
            integers.remove(num);
        }



    }
}
